import java.util.Arrays;

public class OddPrimeSolution {
    public static void main(String[] args) {
        // 创建100以内的奇数数组
        int[] oddNumbers = new int[50]; // 100以内有50个奇数
        for (int i = 0, num = 1; i < 50; i++, num += 2) {
            oddNumbers[i] = num;
        }

        System.out.println("奇数数组: " + Arrays.toString(oddNumbers));

        // 筛选素数
        int primeCount = countPrimes(oddNumbers);
        int[] primes = new int[primeCount];

        int index = 0;
        for (int num : oddNumbers) {
            if (isPrime(num)) {
                primes[index++] = num;
            }
        }

        System.out.println("素数数组: " + Arrays.toString(primes));
        System.out.println("数组b的长度: " + primes.length);
    }

    // 统计数组中的素数个数
    public static int countPrimes(int[] arr) {
        int count = 0;
        for (int num : arr) {
            if (isPrime(num)) {
                count++;
            }
        }
        return count;
    }

    // 判断素数
    public static boolean isPrime(int num) {
        if (num <= 1) return false;
        if (num == 2) return true;
        if (num % 2 == 0) return false;

        for (int i = 3; i * i <= num; i += 2) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}